//
//  WPSearchView.m
//  wobingwoyi
//
//  Created by WGP on 16/7/25.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPSearchView.h"

@interface WPSearchView ()

@property(nonatomic,strong)UITextField *textField;
@property(nonatomic,strong)UIImageView *imageView;
@property(nonatomic,strong)UIButton *coverBtn;

@end

@implementation WPSearchView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        self.layer.cornerRadius = 4;
        self.layer.masksToBounds = YES;
        [self setupUI];
        
    }
    return self;
}

-(void)setupUI
{
//    1.添加子控制件
    self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"main_search"]];
    [self addSubview:self.imageView];
    
    self.textField = [[UITextField alloc] init];
    self.textField.placeholder = @"输入疾病、医院、医生";
    self.textField.font = [UIFont systemFontOfSize:14];
    self.textField.textColor = RGB_SAME(153);
    [self addSubview:self.textField];
    
    self.coverBtn = [[UIButton alloc] init];
    [self.coverBtn addTarget:self action:@selector(coverBtnDidClick) forControlEvents:UIControlEventTouchDown];
    [self addSubview:self.coverBtn];
//    2.设置约束
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leftMargin.mas_equalTo(10);
        make.width.height.mas_equalTo(15);
        make.centerY.equalTo(self);
    }];
    
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageView.mas_right).offset(10);
        make.right.top.bottom.equalTo(self);
    }];
    
    [self.coverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
}

-(void)coverBtnDidClick
{
    if ([self.delegate respondsToSelector:@selector(WPSearchViewDelegate:)]) {
        
        [self.delegate WPSearchViewDelegate:self];
    }
}

@end











